import axios from 'axios'
import { useToken } from '@/stores'
const service = axios.create({
  baseURL: '/api',
  timeout: '10000'
})
// 添加请求拦截器
service.interceptors.request.use((config) => {
  const { getToken } = useToken()
  if (getToken()) {
    config.headers.Authorization = `Bearer ${getToken()}`
  }
  return config
})
// 添加响应拦截器
service.interceptors.response.use(
  (response) => {
    // if (response.data instanceof Blob) {
    //   return response.data
    // }
    return response.data
  },
  (error) => Promise.reject(error)
)
export default service
